﻿TomatoBreak = @TomatoBreak
$ = jQuery

createController = TomatoBreak.ControllerFactory.create
changePage = TomatoBreak.changePage

class DashboardController extends Spine.Controller

    @elements:
        '#todo-list':       'todoList'
        '#activity-sheet':  'activitySheet'
        '#new-task':        'newTask'
        '#edit-task':       'editTask'
        '#reports':         'reports'
        '#settings':        'settings'

    constructor: ->
        super

        createController @todoList, TomatoBreak.ToDoItemsController
        createController @activitySheet, TomatoBreak.TasksController
        createController @newTask, TomatoBreak.TaskController
        createController @editTask, TomatoBreak.TaskController
        createController @reports, TomatoBreak.ReportsController
        createController @settings, TomatoBreak.SettingsController

        @routes
            '!/settings'         : => changePage @settings
            '!/reports'          : => changePage @reports
            '!/tasks/:id/edit'   : (params) =>
                (@editTask.data 'controller').change params.id
                changePage @editTask
            '!/tasks/new'        : => changePage @newTask
            '!/tasks'            : => changePage @activitySheet
            ''                   : => changePage @todoList

        Spine.Route.setup()

$ -> new DashboardController el: $ '#main'